package com.xuetang9.fujian.threaddemo;

import javax.swing.*;

/**
 * @author: fujian
 * @description:
 * @date: 2021/5/2 11:13
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
@SuppressWarnings("all")
public class LanterTask implements Runnable{
    private String title = "";
    private JFrame frame;
    public LanterTask(JFrame frame) {
        this.frame = frame;
        this.title = frame.getTitle();
    }

    @Override
    public void run() {
        StringBuilder sb = new StringBuilder(title);
        while (true){
            sb.insert(0, " ");
            if (sb.toString().length() == 40){
                sb = new StringBuilder(sb.toString().trim());
            }
            frame.setTitle(sb.toString());
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
